﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:services="clr-namespace:ApartmentBillsManager.Start.Services"
                    xmlns:converters="clr-namespace:ApartmentBillsManager.Start.Converters">

    <converters:DateTimeNormalizer x:Key="DateTimeNormalizer"/>
    <converters:RelevantRoommatesConverter x:Key="RelevantRoommatesConverter"/>
    
    <DataTemplate DataType="{x:Type services:CreateEditApartment}">
        <StackPanel Orientation="Vertical">

            <StackPanel Orientation="Horizontal" Margin="10,10,10,5">
                <TextBlock Text="Apartment Name:" Margin="0,0,5,0"/>
                <TextBox Text="{Binding ApartmentName, UpdateSourceTrigger=PropertyChanged}" Width="120"/>
            </StackPanel>

            <StackPanel Margin="10,5,10,10">
                <ListView ItemsSource="{Binding Roommates, UpdateSourceTrigger=PropertyChanged}" Name="RoommatesList" Style="{DynamicResource ShortListViewStyle}" Width="500">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
                            <GridViewColumn Header="Date Of Entrance" DisplayMemberBinding="{Binding DateOfEntrance, Converter={StaticResource DateTimeNormalizer}}"/>
                            <GridViewColumn Header="Date Of Leaving" DisplayMemberBinding="{Binding DateOfLeaving, Converter={StaticResource DateTimeNormalizer}}"/>
                            <GridViewColumn>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="Edit"
                                                Command="{Binding DataContext.EditExistingRoommateCommand, ElementName=RoommatesList}" 
                                                CommandParameter="{Binding}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="Remove"
                                                Command="{Binding DataContext.RemoveExistingRoommateCommand, ElementName=RoommatesList}" 
                                                CommandParameter="{Binding}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>

                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>

                <StackPanel Orientation="Horizontal">
                    <Button Content="Create New Roommate" Margin="0,5,0,0" Command="{Binding CreateNewRoommateCommand}"/>
                </StackPanel>

            </StackPanel>

            <DockPanel HorizontalAlignment="Center" LastChildFill="False" Width="100" Margin="10">
                <Button DockPanel.Dock="Left" Content="Create" Command="{Binding CreateApartmentButtonCommand}" IsEnabled="{Binding CanCreateApartment}"/>
                <Button DockPanel.Dock="Right" Content="Cancel" Command="{Binding CancelApartmentButtonCommand}"/>
            </DockPanel>

        </StackPanel>
    </DataTemplate>


</ResourceDictionary>